/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package denver;

import java.util.ArrayList;
import java.util.Hashtable;

/**
 * Parser commandline arguments
 * @author Denis Lukyanov, skype:denver.fla
 */
public class ArgumentsParser
{
    @SuppressWarnings("UseOfObsoleteCollectionType")
    private Hashtable<String, ArrayList> arguments = null;

    @SuppressWarnings("UseOfObsoleteCollectionType")
    public void parse(String[] args)
    {
        arguments = new Hashtable<String, ArrayList>();
        ArrayList<String> currentArgValues = null;
        for (int i=0; i< args.length; i++)
        {
            if (args[i].startsWith("-"))
            {
                currentArgValues = new ArrayList<String>();
                arguments.put(args[i].toLowerCase().substring(1), currentArgValues);
            } else if (currentArgValues != null) {
                currentArgValues.add(args[i]);
            }
        }

    }

    public boolean hasOption(String option)
    {
        return arguments.containsKey(option);
    }

    public ArrayList<String> getValues(String option)
    {
        ArrayList<String> retval = null;

        if (hasOption(option))
        {
            retval = arguments.get(option);
        }
        
        return retval;
    }

}
